package interview;

import java.util.Scanner;

public class wangyi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        if(n < 3)
            System.out.println(0);
        int ouMAX = nums[0];
        for (int i = 0; i < n; i += 2) {
            if(ouMAX < nums[i])
                ouMAX = nums[i];
        }
        int jiMax = nums[1];
        for (int i = 1; i < n; i += 2) {
            if(jiMax < nums[i])
                jiMax = nums[i];
        }
        int sum = 0;
        for (int i = 0; i < n; i += 2) {
            sum += ouMAX - nums[i];
        }
        for (int i = 1; i < n; i += 2) {
            sum += jiMax - nums[i];
        }
        if(ouMAX == jiMax)
            sum += n / 2;
        System.out.println(sum);
    }
}
/*
6
1 1 4 5 1 4
5
2 1 3 2 4
5
2 1 2 1 2
5
2 2 3 1 5
 */
